package com.wjy.sfhcore.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.wjy.sfhcore.R;
import com.wjy.sfhcore.util.DensityUtil;

/**
 * 导航点控件
 *
 * @author wjy
 */
public class PointView extends RelativeLayout {
    private ImageView iv_point;
    private static final int[] BGS = new int[]{
            R.drawable.lib_logo_pointer_pressed, R.drawable.lib_logo_pointer_normal};
    public static final int VIEW_DIP_SIZE = 10;
    private int viewSize;

    public PointView(Context context) {
        super(context);
        init();
    }

    public PointView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public PointView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(
                R.layout.lib_point_view, null);
        iv_point = (ImageView) view.findViewById(R.id.iv_point);
        viewSize = DensityUtil.dip2px(getContext(), VIEW_DIP_SIZE);
        addView(view, viewSize, viewSize);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(viewSize, viewSize);
        params.setMargins(DensityUtil.dip2px(getContext(), 9), 0, 0, 0);
        setLayoutParams(params);
    }

    public void setSelected(boolean isSelected) {
        if (isSelected) {
            iv_point.setBackgroundResource(BGS[0]);
        } else {
            iv_point.setBackgroundResource(BGS[1]);
        }
    }
}
